<template>
    <div class="layout-padding">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px">
            <el-form-item label="区段：" prop="sectionName">
                <el-tree-select v-model="queryParams.section" :data="dataSource"
                    :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
                    :render-after-expand="false" check-strictly @change="treeChange">
                </el-tree-select>
            </el-form-item>
            <el-form-item label="工区：" prop="workAreaName">
                <el-tree-select v-model="queryParams.workArea" :data="dataSourceArea"
                    :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
                    :render-after-expand="false" check-strictly>
                </el-tree-select>
            </el-form-item>
            <el-form-item label="左/右侧：" prop="leftRight">
                <el-input placeholder="请输入内容" v-model="queryParams.leftRight">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="list">
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column label="区段" align="center" prop="sectionName" />
            <el-table-column label="工区" align="center" prop="workAreaName" />
            <el-table-column label="责任人" align="center" prop="personName" />
            <el-table-column label="护坡地段" align="center" prop="location" />
            <el-table-column label="左/右侧" align="center" prop="leftRight" />
            <el-table-column label="长度" align="center" prop="length" />
            <el-table-column label="高度" align="center" prop="height" />
            <el-table-column label="级数及高度" align="center" prop="level" />
            <el-table-column label="问题描述" align="center" prop="problem" />
            <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script setup>
import { listCutting } from "@/api/system/cutting.js";
import { getTreeList, getDeptBy,delSlope } from "@/api/work";
const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        submited: true,
        section: undefined,
        workArea: undefined,
        leftRight: undefined
    },
    rules: {
        // section: [{ required: true, message: "参数名称不能为空", trigger: "blur" }],
    }
});
const total = ref(0);
const loading = ref(true);
const list = ref([]);
const { proxy } = getCurrentInstance();

const { queryParams, form, rules } = toRefs(data);


//区段数据
const dataSource = ref([])
const dataSourceArea = ref([])
function getTree() {
    getTreeList().then(res => {
        dataSource.value = res.data
    })
}
getTree()

function treeChange(id) {
    queryParams.value.workArea = ''
    form.value.workArea = ''
    getDeptBy({
        parentId: id
    }).then(res => {
        dataSourceArea.value = res.data
    })
}


/** 删除按钮操作 */
function handleDelete(row) {
    const id = row.id;
    proxy.$modal.confirm('是否确认删除id为"' + id + '"的数据项？').then(function () {
        return delSlope(id);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}

/** 查询公告列表 */
function getList() {
    loading.value = true;
    listCutting(queryParams.value).then(response => {
        list.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}


/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

getList();
</script>

<style lang="scss" scoped>
.layout-padding {
    padding: 10px;
}
</style>
